package com.tssm.action.usercenter;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tssm.cache.memcached.TsSessionUtil;
import com.tssm.pojo.SarcFeedback;
import com.tssm.pojo.SarcSupplier;
import com.tssm.service.SarcSupplierService;

@Controller("sarcfeedbackAction")
@Scope("prototype")
public class SarcFeedbackAction extends ActionSupport {

	private static final long serialVersionUID = 715834306517648607L;
	@Resource
	private SarcSupplierService sarcsupplierService;

	private List<SarcFeedback> sflist;

	private Long feedbackid;
	
	private String causeAnalysis;
	
	private String measures;

	private SarcFeedback sarcfeekback;
	
	private String message;
	
	private String view;

	public String findfeedback() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		SarcSupplier nfuser = TsSessionUtil.getTsUser(request);
		if (nfuser != null) {
			sflist = sarcsupplierService.findFeedbackBySupplierName(nfuser
					.getSupplierName());
		}

		return SUCCESS;
	}

	public String editfeedback() throws Exception {
		if (feedbackid != null) {
			sarcfeekback = sarcsupplierService.getFeedbackById(feedbackid);
		}
		return "edit";
	}

	public String updatefeedback() throws Exception {
		boolean flag=false;
		if (feedbackid != null) {
			SarcFeedback feedback = sarcsupplierService
					.getFeedbackById(feedbackid);
			if (feedback!=null){
			feedback.setCauseAnalysis(causeAnalysis);
			feedback.setMeasures(measures);
			feedback.setStatus("1");
			feedback.setFeedbackDate(new Date());
			 flag=sarcsupplierService.saveOrupdateSarcFeedback(feedback);
			}
		if (flag){
			message="success";
		}else{
			message="error";
		}
		}
		return "update";
	}

	public List<SarcFeedback> getSflist() {
		return sflist;
	}

	public void setSflist(List<SarcFeedback> sflist) {
		this.sflist = sflist;
	}

	public Long getFeedbackid() {
		return feedbackid;
	}

	public void setFeedbackid(Long feedbackid) {
		this.feedbackid = feedbackid;
	}

	public SarcFeedback getSarcfeekback() {
		return sarcfeekback;
	}

	public void setSarcfeekback(SarcFeedback sarcfeekback) {
		this.sarcfeekback = sarcfeekback;
	}

	public String getCauseAnalysis() {
		return causeAnalysis;
	}

	public void setCauseAnalysis(String causeAnalysis) {
		this.causeAnalysis = causeAnalysis;
	}

	public String getMeasures() {
		return measures;
	}

	public void setMeasures(String measures) {
		this.measures = measures;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

}
